/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client.service.content;

import han.bifang.gwt.client.common.EntityConstants;
import han.bifang.gwt.client.common.entity.JmsBindingWrapper;
import han.bifang.gwt.client.common.entity.MqJms;
import han.bifang.gwt.client.common.entity.NormalJms;
import han.bifang.gwt.client.service.ServiceMessages;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
import com.google.gwt.user.client.ui.HTMLTable.ColumnFormatter;

/**
 * 
 * @Author Kent
 */
public class ShowJmsPanel extends Composite {

	private ServiceMessages cons;

	
	private SimplePanel infoPanel;

	// private TextBox user;

	// private PasswordTextBox passwd;

	// private ListBox jmsType, jmsServer, jmsVersion;

	private ShowNormalJmsPanel normalJmsPanel;

	private ShowMqJmsPanel mqJmsPanel;

	public ShowJmsPanel(ServiceMessages scons, JmsBindingWrapper w) {
		this.cons = scons;
		
		VerticalPanel panel = new VerticalPanel();
		panel.setWidth("100%");
		infoPanel = new SimplePanel();
		infoPanel.setWidth("100%");

		Grid jms = new Grid(5, 2);
		jms.setCellPadding(1);
		jms.setCellSpacing(1);
		jms.setBorderWidth(1);

		ColumnFormatter cf = jms.getColumnFormatter();
		cf.setWidth(0, "15%");
		cf.setWidth(1, "55%");

		CellFormatter ff = jms.getCellFormatter();
		ff.setStyleName(0, 0, "tablecol");
		ff.setStyleName(1, 0, "tablecol");
		ff.setStyleName(2, 0, "tablecol");
		ff.setStyleName(3, 0, "tablecol");
		ff.setStyleName(4, 0, "tablecol");

		jms.setHTML(0, 0, cons.jmsProvider());
		jms.setHTML(1, 0, cons.version());
		jms.setHTML(2, 0, cons.jmsType());
		jms.setHTML(3, 0, cons.user());
		jms.setHTML(4, 0, cons.password());

		jms.setHTML(0, 1, w.getJmsBinding().getServer());
		jms.setHTML(1, 1, w.getJmsBinding().getServerVersion());
		jms.setHTML(2, 1, w.getJmsBinding().getJmsType().equals(
				EntityConstants.JMS_TYPE_QUEUE) ? cons.queue() : cons.topic());
		jms.setHTML(3, 1, w.getJmsBinding().getJmsUser() == null ? "&nbsp;" : w
				.getJmsBinding().getJmsUser());
		jms.setHTML(4, 1, w.getJmsBinding().getJmsPassword() == null ? "&nbsp;"
				: "******");

		// Window.alert(t.getValue(t.getSelectedIndex()));
		if (w.getJmsBinding().getServer().equals("WebSphere MQ")) {
			mqJmsPanel = new ShowMqJmsPanel(cons, (MqJms) w.getInfo());

			infoPanel.setWidget(mqJmsPanel);
		} else {
				normalJmsPanel = new ShowNormalJmsPanel(cons, (NormalJms) w
						.getInfo());
			
			infoPanel.setWidget(normalJmsPanel);
		}

		panel.add(jms);

		panel.add(new HTML("&nbsp;"));

		panel.add(new HTML(cons.communicateInfo()));

		panel.add(infoPanel);

		initWidget(panel);

	}

	

}
